﻿using System.Windows;
using System.Windows.Input;

namespace MDCAdminTool.Commands
{
    public class ExportConfigCacheCluster : AsyncCommandBindingBase
    {
        public ExportConfigCacheCluster() : base()
        {
            Command = Application.Current.Resources["ExportConfigCacheCluster"] as ICommand;
        }

        protected override void OnExecuted( object sender , ExecutedRoutedEventArgs e )
        {
            var cluster = e.Parameter as CacheCluster;
            if ( cluster != null )
            {
                var dlg = new Microsoft.Win32.SaveFileDialog
                {
                    DefaultExt = ".config" ,
                    Filter     = "Config files (.config)|*.config",
                    FileName   = "CacheCluster.Config" 
                };

                if ( dlg.ShowDialog() ?? false )
                {
                    cluster.ExportConfigFile = dlg.FileName;
                    cluster.ExportConfig();
                }
            }
        }
       
    }
}